package com.atguigu.gmall.activity.controller;

import com.atguigu.gmall.activity.pojo.SeckillOrder;
import com.atguigu.gmall.activity.pojo.UserRecode;
import com.atguigu.gmall.activity.service.SeckillService;
import com.atguigu.gmall.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author luYinLei
 * @version 1.0
 * @date 2021/7/17 9:04
 */
@RestController
@RequestMapping(value = "/seckill/order")
public class SeckillOrderController {

    @Autowired
    private SeckillService seckillService;

    /**
     * 用户下单排队
     * @param time
     * @param skuId
     * @return
     */
    @GetMapping(value = "/addOrder")
    public Result addOrder(String time, String skuId) {
        String userId = "lyl";
        UserRecode userRecode = seckillService.addUserRecode(time, skuId, userId);
        return Result.ok(userRecode);
    }

    /**
     * 查询用户排队信息
     * @return
     */
    @GetMapping(value = "/getUserRecode")
    public Result getUserRecode(){
        String userId = "lyl";
        UserRecode userRecode = seckillService.getUserRecode(userId);
        return Result.ok(userRecode);
    }

    /**
     * 查询秒杀订单信息
     * @param orderId
     * @return
     */
    @GetMapping(value = "/getSeckillOrderList")
    public Result getSeckillOrderList(String orderId){
        String userId = "lyl";
        List<SeckillOrder> seckillOrderList = seckillService.getSeckillOrderList(userId, orderId);
        return Result.ok(seckillOrderList);
    }
}
